package com.hengpeng.itfints.controller.index;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import com.hengpeng.common.exception.ServiceResult;
import com.hengpeng.itfinbase.en.BorrowStatus;
import com.hengpeng.itfinbase.persist.BorrowInfo;
import com.hengpeng.itfinbase.persist.Links.LinkType;
import com.hengpeng.itfints.controller.BaseController;

@Controller
@RequestMapping("/main")
public class MainController extends BaseController {

    @RequestMapping("/findLinks")
    public String links(ModelMap map, HttpServletRequest request) {
        String backurl = request.getParameter("backurl");
        String[] field = new String[] { "url", "name", "logo" };
        List<Object> navigationList = serviceFactory.getLinksService().findLinksByType(LinkType.NAVIGATION, field);
        List<Object> partnersList = serviceFactory.getLinksService().findLinksByType(LinkType.PARTNERS, field);
        List<Object> linksList = serviceFactory.getLinksService().findLinksByType(LinkType.LINKS, field);
        map.put("NAVIGATION", navigationList);
        map.put("PARTNERS", partnersList);
        map.put("LINKS", linksList);
        // 返回路径
        if (backurl != null) {// 返回路径不为空时返回指定位置
            return backurl;
        } else {
            return "/page/include/links.jsp";
        }
    }

    @RequestMapping("/product")
    public String product(ModelMap map, HttpServletRequest request) {
        BorrowStatus[] status = { BorrowStatus.RAISE, BorrowStatus.END, BorrowStatus.LOANING,
                BorrowStatus.REPAYMENTING, BorrowStatus.REPAYMENTED };
        ServiceResult<List<BorrowInfo>> serviceResult = serviceFactory.getBorrowInfoService().queryList(status, null,
                1, 4, null, null, null, null, null, null);
        map.put("productList", serviceResult.getReturnValue());
        return "/page/include/index_product.jsp";
    }
}
